package com.erms.lab.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.erms.common.annotation.Log;
import com.erms.common.enums.BusinessType;
import com.erms.lab.domain.LabMajorTwo;
import com.erms.lab.service.ILabMajorTwoService;
import com.erms.common.core.controller.BaseController;
import com.erms.common.core.domain.AjaxResult;
import com.erms.common.utils.poi.ExcelUtil;
import com.erms.common.core.page.TableDataInfo;

/**
 * 专业机房二Controller
 * 
 * @author smile
 * @date 2020-05-04
 */
@Controller
@RequestMapping("/lab/major_two")
public class LabMajorTwoController extends BaseController
{
    private String prefix = "lab/major_two";

    @Autowired
    private ILabMajorTwoService labMajorTwoService;

    @RequiresPermissions("lab:major_two:view")
    @GetMapping()
    public String major_two()
    {
        return prefix + "/major_two";
    }

    /**
     * 查询专业机房二列表
     */
    @RequiresPermissions("lab:major_two:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LabMajorTwo labMajorTwo)
    {
        startPage();
        List<LabMajorTwo> list = labMajorTwoService.selectLabMajorTwoList(labMajorTwo);
        return getDataTable(list);
    }

    /**
     * 导出专业机房二列表
     */
    @RequiresPermissions("lab:major_two:export")
    @Log(title = "专业机房二", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LabMajorTwo labMajorTwo)
    {
        List<LabMajorTwo> list = labMajorTwoService.selectLabMajorTwoList(labMajorTwo);
        ExcelUtil<LabMajorTwo> util = new ExcelUtil<LabMajorTwo>(LabMajorTwo.class);
        return util.exportExcel(list, "major_two");
    }

    /**
     * 新增专业机房二
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存专业机房二
     */
    @RequiresPermissions("lab:major_two:add")
    @Log(title = "专业机房二", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LabMajorTwo labMajorTwo)
    {
        return toAjax(labMajorTwoService.insertLabMajorTwo(labMajorTwo));
    }

    /**
     * 修改专业机房二
     */
    @GetMapping("/edit/{equipId}")
    public String edit(@PathVariable("equipId") Long equipId, ModelMap mmap)
    {
        LabMajorTwo labMajorTwo = labMajorTwoService.selectLabMajorTwoById(equipId);
        mmap.put("labMajorTwo", labMajorTwo);
        return prefix + "/edit";
    }

    /**
     * 修改保存专业机房二
     */
    @RequiresPermissions("lab:major_two:edit")
    @Log(title = "专业机房二", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LabMajorTwo labMajorTwo)
    {
        return toAjax(labMajorTwoService.updateLabMajorTwo(labMajorTwo));
    }

    /**
     * 删除专业机房二
     */
    @RequiresPermissions("lab:major_two:remove")
    @Log(title = "专业机房二", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(labMajorTwoService.deleteLabMajorTwoByIds(ids));
    }
}
